package com.lianzhihui.romeex.utils;

import android.app.Dialog;
import android.content.res.Resources;
import android.util.DisplayMetrics;
import android.view.ViewGroup;
import android.view.Window;

import com.lianzhihui.romeex.R;

/**
 * Description: dialog动画工具
 * Author: RAMON
 * CreateDate: 2020/11/5 5:06 PM
 * UpdateUser:
 * UpdateDate:
 * UpdateRemark:
 * Version:
 */
public class DialogUtil {

    public static void setWindowFull(Dialog dialog) {
        Window window = dialog.getWindow();

        Resources resources = dialog.getContext().getResources();
        DisplayMetrics dm = resources.getDisplayMetrics();
        float density = dm.density;
        int width = dm.widthPixels;
        int screenHeight = dm.heightPixels;

        int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android");
        int statusBarHeight = resources.getDimensionPixelSize(resourceId);

        int dialogHeight = screenHeight - statusBarHeight;
        window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, dialogHeight == 0 ? ViewGroup.LayoutParams.MATCH_PARENT : dialogHeight);
        window.setBackgroundDrawableResource(R.color.transparent);
    }

    /**
     * 水平max
     *
     * @param dialog
     */
    public static void setWindowMW(Dialog dialog) {
        Window window = dialog.getWindow();

//        Resources resources = dialog.getContext().getResources();
//        DisplayMetrics dm = resources.getDisplayMetrics();
//        float density = dm.density;
//        int width = dm.widthPixels;
//        int screenHeight = dm.heightPixels;
//
//        int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android");
//        int statusBarHeight = resources.getDimensionPixelSize(resourceId);
//
//        int dialogHeight = screenHeight - statusBarHeight;



        window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        window.setBackgroundDrawableResource(R.color.transparent);
    }

    /**
     * 上到下
     *
     * @param dialog
     */
    public static void setT2B(Dialog dialog) {
        Window window = dialog.getWindow();
        window.setWindowAnimations(R.style.dialog_animation);
    }

    /**
     * 下到上
     *
     * @param dialog
     */
    public static void setB2T(Dialog dialog) {
        Window window = dialog.getWindow();
        window.setWindowAnimations(R.style.dialogWindowAnimButtomToTop);
    }

}


